package com.example.sanjixianmu_zzm_408.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.sanjixianmu_zzm_408.R;
import com.example.sanjixianmu_zzm_408.iface.RegisterListener;
import com.example.sanjixianmu_zzm_408.model.RegisterModel;


public class RegisterActivity extends AppCompatActivity implements RegisterListener,View.OnClickListener{
    private EditText et_userName, et_password, et_rePassword, et_tel;
    private Button btn_return, btn_register;
    private Context context;
    private SharedPreferences preferences;
    final static String PREF_NAME="loginPref";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        initView();
    }

    private void initView() {
        et_password=(EditText)findViewById(R.id.et_password);
        et_userName=(EditText)findViewById(R.id.et_username);
        et_rePassword=(EditText)findViewById(R.id.et_rePassword);
        et_tel=(EditText)findViewById(R.id.et_tel);
        btn_register=(Button)findViewById(R.id.btn_register);
        btn_register.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch ((v.getId())){
            case R.id.btn_register:
                String userName=et_userName.getText().toString();
                String password1=et_password.getText().toString();
                String password2=et_rePassword.getText().toString();
                if (!password1.equals(password2)){
                    et_rePassword.setError("密码不一致");
                    return;
                }
                String tel=et_tel.getText().toString();
                RegisterModel mode=new RegisterModel();
                mode.register(userName,password1,tel,this);
                break;
            case R.id.btn_return:
                Intent intent=new Intent(context,LoginActivity.class);
        }

    }

    @Override
    public void onResponse(String regInfo) {
        Toast.makeText(this,regInfo,Toast.LENGTH_SHORT).show();

    }

    @Override
    public void onFail(String msg) {

    }
}

